package lm.concurrency.day2.synchronizedDemos;

import lombok.extern.slf4j.Slf4j;

/**
 * @Auther: Min.Liu
 * @Description:  synchronized解决问题  面向对象
 * @Date: Created in 10:50 2024/11/5
 */
@Slf4j
public class Demo3 {
    public static void main(String[] args) throws InterruptedException {
        Room room = new Room();
        Thread t1 = new Thread(() -> {
            for (int j = 0; j < 5000; j++) {
                room.increment();
            }
        }, "t1");

        Thread t2 = new Thread(() -> {
            for (int j = 0; j < 5000; j++) {
                room.decrement();
            }
        }, "t2");
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        log.debug("count: {}", room.get());
    }
}

